package com.zhang.gmall.realtime.utils;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

/**
 * @title:  分词器工具类
 * @author: zhang
 * @date: 2022/3/16 19:46
 */
public class KeywordUtil {
    public static List<String> analyze(String text){
        ArrayList<String> keywordList = new ArrayList<>();
        StringReader reader = new StringReader(text);
        IKSegmenter ikSegmenter = new IKSegmenter(reader, true);
        try {
            Lexeme lexeme = null;
            while ((lexeme = ikSegmenter.next()) != null){
                keywordList.add(lexeme.getLexemeText());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return keywordList;
    }


    public static void main(String[] args) {
        System.out.println(analyze("图书,Flink,SparkStreaming,MacBookPro,数仓工具箱,Hadoop,Hive"));
    }
}
